<?php

// +-----------------------------------------------------------------------
// | @Copyright (c) 2012 http://t00ls.net.
// +-----------------------------------------------------------------------
// | @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +-----------------------------------------------------------------------
// | @author: lenush <jnicklasj@gmail.com> qq:707207845
// +-----------------------------------------------------------------------

final class Gos_Controller_Finance extends Gospel_Controller_Api {

    public function index() {
//        学费月收入
//        
//        学费周收入
//        年书本收入
//        
//        年其他收入
//        年日常支出
//        
//        月日常支出
//        
//        周日常支出
//        年其他支出

        $this->tpl->draw('finance/index');
    }

    public function yearin() {
        //学费年收入
        $return = null;
        $year_in = new Gos_Model_Student();
        $between['begin'] = date('Y-01-01 00:00:00');
        $between['end'] = date('Y-12-31 23:59:59');
        $begin_this_year = strtotime($between['begin']);
        $end_this_year = strtotime($between['end']);
        $year_in_where = sprintf("createat BETWEEN %s AND %s", $begin_this_year, $end_this_year);
        $offset = $this->getRequest()->getInt('parameters') == 0 ? 1 : $this->getRequest()->getInt('parameters');
        $offset = $offset == 0 ? 0 : ($offset - 1) * 15;
        $return = $year_in->getList($year_in_where, 'id DESC', $offset);
//      时间范围
        $return['between'] = $between;
//      招生人数
        $return['students'] = $return['pager']['rtotal'];
//      招生收入

        $return['totalfee'] = 220000;
        throw new Gospel_Controller_Api_Exception(200, 'ok', $return);
    }

    public function monthin() {
        //学费年收入
        $return = null;
        $year_in = new Gos_Model_Student();
        $monthday = date("t");
        $month_times = strtotime(date("Y-m"));
        $between['begin'] = date('Y-m-01 00:00:00');
        $between['end'] = date("Y-m-$monthday 23:59:59", strtotime("this month", $month_times));
        $begin_this_month = strtotime(date('Y-m-01 00:00:00'));
        $end_this_month = strtotime(date("Y-m-$monthday 23:59:59", strtotime("this month", $month_times)));
        $month_in_where = sprintf("createat BETWEEN %s AND %s", $begin_this_month, $end_this_month);
        $offset = $this->getRequest()->getInt('parameters') == 0 ? 1 : $this->getRequest()->getInt('parameters');
        $offset = $offset == 0 ? 0 : ($offset - 1) * 15;
        $return = $year_in->getList($month_in_where, 'id DESC', $offset);
//      时间范围
        $return['between'] = $between;
//      招生人数
        $return['students'] = $return['pager']['rtotal'];
//      招生收入

        $return['totalfee'] = 220000;
        throw new Gospel_Controller_Api_Exception(200, 'ok', $return);
    }

    public function weekin() {
        //学费年收入
        $return = null;
        $week_in = new Gos_Model_Student();
        $day = date('d');
        $mon = date('m');
        $year = date('Y');
        $today = date('N');
        $begin_this_week = strtotime(date('Y-m-d', mktime(0, 0, 0, $mon, $day - $today + 1, $year)));
        $end_this_week = strtotime(date('Y-m-d H:i:s', mktime(23, 59, 59, $mon, $day - $today + 7, $year)));
        $between['begin'] = date('Y-m-d', mktime(0, 0, 0, $mon, $day - $today + 1, $year));
        $between['end'] = date('Y-m-d H:i:s', mktime(23, 59, 59, $mon, $day - $today + 7, $year));
        $week_in_where = sprintf("createat BETWEEN %s AND %s", $begin_this_week, $end_this_week);
        $offset = $this->getRequest()->getInt('parameters') == 0 ? 1 : $this->getRequest()->getInt('parameters');
        $offset = $offset == 0 ? 0 : ($offset - 1) * 15;
        $return = $week_in->getList($week_in_where, 'id DESC', $offset);
//      时间范围
        $return['between'] = $between;
//      招生人数
        $return['students'] = $return['pager']['rtotal'];
//      招生收入

        $return['totalfee'] = 220000;
        throw new Gospel_Controller_Api_Exception(200, 'ok', $return);
    }

}

/**
* // +---------------------------------------------------------------------
* // | @ Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
* // +---------------------------------------------------------------------
* // | @ author: lenush <jnicklasj@gmail.com> qq:707207845
* // +---------------------------------------------------------------------
* Local variables:
* tab-width:4
* basic-offset:4
* indent-tabs-mode:t
* End:
*/
